package com.pkx.cloud.fse7.dms.emview.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.pkx.cloud.fse7.dms.emview.entity.RpDmsTokenEmGrantView;
import com.pkx.cloud.fse7.dms.emview.repo.RpDmsTokenEmGrantViewMapper;
import com.pkx.cloud.fse7.dms.emview.service.RpDmsTokenEmGrantViewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
 *  服务实现类
 *
 * @author zhangwh
 * @since 2020-10-16
 */
@Service
public class RpDmsTokenEmGrantViewServiceImpl extends ServiceImpl<RpDmsTokenEmGrantViewMapper, RpDmsTokenEmGrantView> implements RpDmsTokenEmGrantViewService {

    /**
     * 分页列表
     * @param page
     * @param issueStratDate
     * @param issueEndDate
     * @param staffName
     * @param tokenId
     * @return
     * @throws ParseException
     */
    @Override
    public Page<RpDmsTokenEmGrantView> pageList(Page page, String issueStratDate, String issueEndDate, String staffName, String tokenId) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate=new Date();
        Date endDate=new Date();
        if(StringUtils.isNotBlank(issueStratDate)&&StringUtils.isNotBlank(issueEndDate)){
             startDate = sdf.parse(issueStratDate);
             endDate = sdf.parse(issueEndDate);
        }
        LambdaQueryWrapper<RpDmsTokenEmGrantView> lambdaQueryWrapper = Wrappers.lambdaQuery(RpDmsTokenEmGrantView.class)
                //人员名称
                .eq(StringUtils.isNotBlank(staffName),RpDmsTokenEmGrantView::getStaffName,staffName)
                //凭证号
                .eq(StringUtils.isNotBlank(tokenId),RpDmsTokenEmGrantView::getTokenId,tokenId)
                //操作时间
                .between(StringUtils.isNotBlank(issueStratDate)&&StringUtils.isNotBlank(issueEndDate),RpDmsTokenEmGrantView::getIssueDate,startDate,endDate);
        return page(page, lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @param rpDmsTokenEmGrantView
     * @return
     */
    @Override
    public List<RpDmsTokenEmGrantView> listByEntity(RpDmsTokenEmGrantView rpDmsTokenEmGrantView) {
        LambdaQueryWrapper<RpDmsTokenEmGrantView> lambdaQueryWrapper = Wrappers.lambdaQuery(RpDmsTokenEmGrantView.class);
        return list(lambdaQueryWrapper);
    }

}
